package team.knowers.qzh.qzhadmin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import team.knowers.qzh.qzhadmin.dao.entity.ChapterDO;
import team.knowers.qzh.qzhadmin.dao.mapper.ChapterMapper;
import team.knowers.qzh.qzhadmin.dto.resp.AllChapterRespDTO;
import team.knowers.qzh.qzhadmin.service.ChapterAdminService;

import java.util.ArrayList;
import java.util.List;

@Service
@AllArgsConstructor
public class ChapterAdminServiceImpl extends ServiceImpl<ChapterMapper, ChapterDO> implements ChapterAdminService {
    @Override
    public List<AllChapterRespDTO> showAllChapter(Long id) {
        LambdaQueryWrapper<ChapterDO> queryWrapper= Wrappers.lambdaQuery(ChapterDO.class)
                .eq(ChapterDO::getCourseId,id)
                .eq(ChapterDO::getDelFlag,0)
                .orderByAsc(ChapterDO::getOrder);
        List<ChapterDO> chapterDOS=baseMapper.selectList(queryWrapper);
        List<AllChapterRespDTO> chapterDTOs = new ArrayList<>();
        for (ChapterDO chapterDO :chapterDOS) {
            AllChapterRespDTO chapterDTO = new AllChapterRespDTO();
            chapterDTO.setOrder(chapterDO.getOrder());
            chapterDTO.setName(chapterDO.getName());
            chapterDTO.setId(chapterDO.getId());
            chapterDTOs.add(chapterDTO);
        }

        return chapterDTOs;
    }
}
